package com.atguigu.dao.impl;

import com.atguigu.dao.NginxServiceConfigTcpProxyDao;
import com.atguigu.pojo.NginxServiceConfigTcpProxy;

import java.util.List;

public class NginxServiceConfigTcpProxyDaoImpl extends BaseDao implements NginxServiceConfigTcpProxyDao {
    @Override
    public int addNginxServiceConfigTcpProxy(NginxServiceConfigTcpProxy nginxServiceConfigTcpProxy) {
        System.out.println("NginxServiceConfigTcpProxyDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_nginxServiceConfigTcpProxy(`id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use`) values(?,?,?,?,?,?,?,?);";
            return update(sql,nginxServiceConfigTcpProxy.getId(),nginxServiceConfigTcpProxy.getServerId(),
                    nginxServiceConfigTcpProxy.getServiceId(),nginxServiceConfigTcpProxy.getFrontDomain(),
                    nginxServiceConfigTcpProxy.getFrontPort(),nginxServiceConfigTcpProxy.getEndAddress(),nginxServiceConfigTcpProxy.getEndPort(),nginxServiceConfigTcpProxy.getUse());
    }

    @Override
    public int deleteNginxServiceConfigTcpProxyById(String id) {
        String sql="delete from t_nginxServiceConfigTcpProxy where id=?";
        return update(sql,id);
    }

    @Override
    public int updateNginxServiceConfigTcpProxy(NginxServiceConfigTcpProxy nginxServiceConfigTcpProxy) {
        String sql="update t_nginxServiceConfigTcpProxy set `serverId`=?,`serviceId`=?,`frontDomain`=?,`frontPort`=?,`endAddress`=?,`endPort`=? ,`use`=? where id=?";
        return update(sql,nginxServiceConfigTcpProxy.getServerId(),
                nginxServiceConfigTcpProxy.getServiceId(),nginxServiceConfigTcpProxy.getFrontDomain(),
                nginxServiceConfigTcpProxy.getFrontPort(),nginxServiceConfigTcpProxy.getEndAddress(),
                nginxServiceConfigTcpProxy.getEndPort(),nginxServiceConfigTcpProxy.getUse(),nginxServiceConfigTcpProxy.getId());
    }

    @Override
    public NginxServiceConfigTcpProxy queryNginxServiceConfigTcpProxyById(String id) {
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy where id=?";
        return queryForOne(NginxServiceConfigTcpProxy.class,sql,id);
    }

    @Override
    public List<NginxServiceConfigTcpProxy> queryNginxServiceConfigTcpProxys() {
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy";
        return queryForList(NginxServiceConfigTcpProxy.class,sql);
    }
    @Override
    public List<NginxServiceConfigTcpProxy> queryNginxServiceConfigTcpProxiesByServiceId(String serviceId){
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy where serviceId =?";
        return queryForList(NginxServiceConfigTcpProxy.class,sql,serviceId);
    }
    @Override
    public List<NginxServiceConfigTcpProxy> queryNginxServiceConfigTcpProxiesByFrontPort(String frontPort) {
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy where frontPort =?";
        return queryForList(NginxServiceConfigTcpProxy.class,sql,frontPort);
    }
    @Override
    public List<NginxServiceConfigTcpProxy> queryNginxServiceConfigTcpProxiesByServiceIdFrontDomainPort(String serviceId,String frontDomain,String frontPort) {
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy where serviceId =? and frontDomain =? and frontPort =?";
        return queryForList(NginxServiceConfigTcpProxy.class,sql,serviceId,frontDomain,frontPort);
    }
    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_nginxServiceConfigTcpProxy";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<NginxServiceConfigTcpProxy> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`serverId`,`serviceId`,`frontDomain`,`frontPort`,`endAddress`,`endPort`,`use` from t_nginxServiceConfigTcpProxy limit ?,?";
        return queryForList(NginxServiceConfigTcpProxy.class,sql,begin,pageSize);

    }
}
